package root.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import root.entity.vo.PageInfo;
import root.service.LybDataService;
import root.service.impl.LybDataServiceimpl;

/**
 * Servlet implementation class Lybsenddata
 */
@WebServlet("/lybsenddata")
public class Lybsenddata extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Lybsenddata() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter(); 
		
		//获取信息
		String name = request.getParameter("name");
		String value = request.getParameter("value");
		String type = request.getParameter("type");
		String target = request.getParameter("target");
		String ip = request.getRemoteAddr();
		
	
		//检查数据为空
		if(type==null || type.equals("")) {
			writer.write("error");
			writer.close();
			return;
		}
		if(value==null || value.equals("")) {
			writer.write("error");
			writer.close();
			return;
		}

		
		//执行业务
		LybDataService service = new LybDataServiceimpl();
		boolean boo = service.sendData(name,value,type,target,ip);
		
		if(boo) {
			writer.write("{\"code\":200}");
		}else {
			writer.write("{\"code\":400,\"msg\":\"error\"}");
		}
		writer.close();
		return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
